<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h1>组件使用v-model</h1>
    <p>value: {{ value }}</p>

    <hr>

    <child :value="value" @get-new-value="getValue"></child>
  </div>

  <script src="../Vue.js"></script>

  <script>
    const { createApp } = Vue;

    const Child = {
      props: {
        value: String,
      },
      template: `
        <input type="text" :value="value" @input="change($event)" />
      `,
      methods: {
        change(e) {
          // console.log(e.target.value);
          this.$emit("getNewValue", e.target.value)
        }
      }
    }
    
    const app = createApp({
      data() {
        return {
          value: "11199"
        }
      },
      methods: {
        getValue(v) {
          console.log(v);
          this.value = v
        }
      },
      components: {
        Child
      }
    })

    app.mount("#app")
  </script>
</body>
</html>